package com.ruoyi.zhongkao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhongkao.domain.ZkCandidateCategory;
import com.ruoyi.zhongkao.service.IZkCandidateCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考生类别Controller
 * 
 * @author ruoyi
 * @date 2025-07-04
 */
@Api(tags = "中考-考生类别管理")
@RestController
@RequestMapping("/zhongkao/category")
public class ZkCandidateCategoryController extends BaseController
{
    @Autowired
    private IZkCandidateCategoryService zkCandidateCategoryService;
    //查询所有考生类别不分页
    @GetMapping("/all")
        @ApiOperation("中考考生类别管理 - 查询所有数据")
    public AjaxResult getAll()
        {// 调用服务层获取所有类别数据
            List<ZkCandidateCategory> list = zkCandidateCategoryService.selectZkCandidateCategoryAll();
            // 返回成功结果（AjaxResult是封装的统一返回对象）
            return success(list);
        }
    /**
     * 查询考生类别列表
     */
    //@PreAuthorize("@ss.hasPermi('zhongkao:category:list')")
    @GetMapping("/list")
        @ApiOperation("中考考生类别管理 - 分页查询列表")
    public TableDataInfo list(ZkCandidateCategory zkCandidateCategory)
    {
        startPage();
        List<ZkCandidateCategory> list = zkCandidateCategoryService.selectZkCandidateCategoryList(zkCandidateCategory);
        return getDataTable(list);
    }

    /**
     * 导出考生类别列表
     */
    @PreAuthorize("@ss.hasPermi('zhongkao:category:export')")
    @Log(title = "考生类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
        @ApiOperation("中考考生类别管理 - 导出数据")
    public void export(HttpServletResponse response, ZkCandidateCategory zkCandidateCategory)
    {
        List<ZkCandidateCategory> list = zkCandidateCategoryService.selectZkCandidateCategoryList(zkCandidateCategory);
        ExcelUtil<ZkCandidateCategory> util = new ExcelUtil<ZkCandidateCategory>(ZkCandidateCategory.class);
        util.exportExcel(response, list, "考生类别数据");
    }

    /**
     * 获取考生类别详细信息
     */
    //@PreAuthorize("@ss.hasPermi('zhongkao:category:query')")
    @GetMapping(value = "/{id}")
        @ApiOperation("中考考生类别管理 - 根据ID获取详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zkCandidateCategoryService.selectZkCandidateCategoryById(id));
    }
    @GetMapping("/selectByCode/{code}")
        @ApiOperation("中考考生类别管理 - getCode")
    public AjaxResult getCode(@PathVariable("code") String code)
    {
        return success(zkCandidateCategoryService.selectZkCandidateCategoryByCode(code));
    }

    /**
     * 新增考生类别
     */
    //@PreAuthorize("@ss.hasPermi('zhongkao:category:add')")
    @Log(title = "考生类别", businessType = BusinessType.INSERT)
    @PostMapping
        @ApiOperation("中考考生类别管理 - 新增数据")
    public AjaxResult add(@RequestBody ZkCandidateCategory zkCandidateCategory)
    {
        return toAjax(zkCandidateCategoryService.insertZkCandidateCategory(zkCandidateCategory));
    }

    /**
     * 修改考生类别
     */
    //@PreAuthorize("@ss.hasPermi('zhongkao:category:edit')")
    @Log(title = "考生类别", businessType = BusinessType.UPDATE)
    @PutMapping
        @ApiOperation("中考考生类别管理 - 修改数据")
    public AjaxResult edit(@RequestBody ZkCandidateCategory zkCandidateCategory)
    {
        return toAjax(zkCandidateCategoryService.updateZkCandidateCategory(zkCandidateCategory));
    }

    /**
     * 删除考生类别
     */
    @PreAuthorize("@ss.hasPermi('zhongkao:category:remove')")
    @Log(title = "考生类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
        @ApiOperation("中考考生类别管理 - 删除数据")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zkCandidateCategoryService.deleteZkCandidateCategoryByIds(ids));
    }
}
